<%@page import="com.util.Pagination"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page import="com.util.DbUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="../js/js.js"></script>
<style type="text/css">
<!--
body {
	margin-left: 3px;
	margin-top: 0px;
	margin-right: 3px;
	margin-bottom: 0px;
}
.STYLE1 {
	color: #e1e2e3;
	font-size: 12px;
}
.STYLE6 {color: #000000; font-size: 12; }
.STYLE10 {color: #000000; font-size: 12px; }
.STYLE19 {
	color: #344b50;
	font-size: 12px;
}
.STYLE21 {
	font-size: 12px;
	color: #3b6375;
}
.STYLE22 {
	font-size: 12px;
	color: #295568;
}
-->
</style>
<script type="text/javascript">
	function add() {
		window.location.href = "user_info_add.jsp";
	}
	function del() {
		var selectFlags  = document.getElementsByName("selectFlag");
		var flag = false;
		for (var i=0; i<selectFlags.length; i++) {
			if (selectFlags[i].checked) {
				flag = true;
				break;
			}
		}
		if (!flag) {
			alert("请选择需要删除的记录！");
			return;
		}
		if (window.confirm("确认删除吗？")) {
			with (document.getElementById("form")) {
				action="UserInfoServlet?method=del";
				method="post";
				submit();
			}
		}
	}
	function modify() {
		var selectFlags = document.getElementsByName("selectFlag");
		var count = 0;
		var j = 0;
		for ( var i = 0; i < selectFlags.length; i++) {
			if (selectFlags[i].checked) {
				j = i;
				count++;
			}
		}
		if (count == 0) {
			alert("请选择需要修改的记录！");
			return;
		}
		if (count > 1) {
			alert("一次只能修改一条记录！");
			return;
		}
		window.location.href = "user_info_modify.jsp?id=" + selectFlags[j].value;;
	}
</script>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="24" bgcolor="#353c44"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="6%" height="19" valign="bottom"><div align="center"><img src="../images/tb.gif" width="14" height="14" /></div></td>
                <td width="94%" valign="bottom"><span class="STYLE1"> 基本信息列表</span></td>
              </tr>
            </table></td>
            <td>
            	<jsp:include page="top_banner.jsp" />
              </td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>
    <form name="form" id="form">
    <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
      <tr>
        <td width="4%" height="20" bgcolor="d3eaef" class="STYLE10"><div align="center">
          &nbsp;
        </div></td>
        <td width="10%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">编号</span></div></td>
        <td width="15%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">帐号</span></div></td>
        <td width="14%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">密码</span></div></td>
        <td width="14%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">角色</span></div></td>
        <td width="14%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">姓名</span></div></td>
        <td width="14%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">性别</span></div></td>
        <td width="14%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">职称</span></div></td>
      </tr>
      <%
		/**
		 * 分页begin
		 */
		final int pageSize = 10; // 一页显示 10 条记录

		int pageNum = 1; // 当前页数
		int pageCount = 1; // 总页数

		int recordCount = 0; // 总记录数

		String strAbsPath = application.getRealPath(request.getRequestURI()); // 获得当前文件的绝对路径名
		int endIndex = strAbsPath.length();
		int beginIndex = strAbsPath.lastIndexOf("\\") + 1;
		String pageUrl = strAbsPath.substring(beginIndex, endIndex); // 获取当前文件名，如：xxx.jsp,或者 xxx.html

		try {
			// 从地址栏参数取当前页数
			if (request.getParameter("pageNum") == null) {
				pageNum = 1;
			} else {
				pageNum = Integer.parseInt(request.getParameter("pageNum"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		recordCount = DbUtil.getCount("t_user_info");
		// 计算总页数
		pageCount = (recordCount + pageSize - 1) / pageSize;
		// 本页从 startRecord 行开始
		int startRecord = (pageNum - 1) * pageSize;
		/**
		 * 分页end
		 */
		int num = 1;
		String sql = "select * from t_user_info order by id asc limit "
								+ startRecord + " ," + pageSize;
						
		List<Map<String, Object>> list = DbUtil.find(sql);
		Map<String, Object> map = null;
		for (int i = 0; i < list.size(); i++) {
			map = (Map<String, Object>)list.get(i);
	%>
      <tr>
        <td height="20" bgcolor="#FFFFFF"><div align="center">
          <input type="checkbox" name="selectFlag" value="<%=map.get("id")%>" id="checkbox2" />
        </div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE6"><div align="center"><span class="STYLE19"><%=map.get("id") %></span></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><%=map.get("account") %></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><%=map.get("pswd") %></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><%=map.get("role") %></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><%=map.get("name") %></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><%=map.get("sex") %></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><%=map.get("title") %></div></td>
      </tr>
   <% 
	} 
   %> 
    </table>
    </form>
    </td>
  </tr>
  <tr>
    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="40%"><div align="left"><span class="STYLE22">&nbsp;&nbsp;&nbsp;&nbsp;<%=Pagination.getPagination(pageNum, pageCount, recordCount,pageUrl)%></span></div></td>
        <td width="60%"><table width="312" border="0" align="right" cellpadding="0" cellspacing="0">
          <tr>
            <td width="49"><div align="center"><!-- <img src="../images/main_54.gif" width="40" height="15" /> --></div></td>
            <td width="49"><div align="center"><!-- <img src="../images/main_56.gif" width="45" height="15" /> --></div></td>
            <td width="49"><div align="center"><!-- <img src="../images/main_58.gif" width="45" height="15" /> --></div></td>
            <td width="49"><div align="center"><!-- <img src="../images/main_60.gif" width="40" height="15" /> --></div></td>
            <td width="37" class="STYLE22"><!-- <div align="center">转到</div> --></td>
            <td width="22"><div align="center">
              <!-- <input type="text" name="textfield" id="textfield"  style="width:20px; height:12px; font-size:12px; border:solid 1px #7aaebd;"/> -->
            </div></td>
            <td width="22" class="STYLE22"><!-- <div align="center">页</div> --></td>
            <td width="35"><!-- <img src="../images/main_62.gif" width="26" height="15" /> --></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
